Start when sensor W-M Start is active
# Set train #12 at the station
If sensor SimMode is active
    Set block Watertown Station occupied
Endif
Assign long address 1234 as #12 in Watertown Station
Wait for 5 seconds
Print ++++ setup done for train 12
Loop
    Print ++++ do a loop
    # Get access to the junction
    Wait for sensor Reserve Open to become active
    Set sensor Reserve WM active

    # Start moving
    Set turnout Winthrop Junction closed
    Set turnout Mpls Depot closed
    Set function key 0 on
    Set direction to forward
    Set speed to .5

    If sensor SimMode is active
        # Move the train to Winthrop
        Set block Watertown East occupied
        Wait for 1 second
        Set block Watertown Station unoccupied
        Wait for 1 second
        Set block Winthrop Junction occupied
        Wait for 1 second
        Set block Watertown East unoccupied
        Wait for 1 second
        Set block Winthrop Station occupied
        Wait for 1 second
        Set block Winthrop Junction unoccupied
    Endif

    # Station stop
    Wait for sensor Winthrop Station to become active
    Set speed to 0
    Wait for 5 seconds
    Set speed to .6

    If sensor SimMode is active
        # Move the train to Mpls
        Set block Mpls West occupied
        Wait for 1 second
        Set block Winthrop Station unoccupied
        Wait for 1 second
        Set block Mpls Depot occupied
        Wait for 1 second
        Set block Mpls West unoccupied
        Wait for 1 second
        Set block Mpls Track 1 occupied
        Wait for 1 second
        Set block Mpls Depot unoccupied
        Wait for 1 second
    Endif

    Wait for sensor Mpls Track 1 to become active
    # Release the reservation
    Set sensor Reserve Open active
    Set speed to 0
    Wait for 10 seconds

    # Get access to the junction
    Wait for sensor Reserve Open to become active
    Set sensor Reserve WM active

    # Set the turnouts and proceed
    Set turnout Mpls Depot closed
    Set turnout Winthrop Junction closed
    Set direction to reverse
    Set speed to .4

    If sensor SimMode is active
        # Move the train to Winthrop
        Set block Mpls Depot occupied
        Wait for 1 second
        Set block Mpls Track 1 unoccupied
        Wait for 1 second
        Set block Mpls West occupied
        Wait for 1 second
        Set block Mpls Depot unoccupied
        Wait for 1 second
        Set block Winthrop Station occupied
        Wait for 1 second
        Set block Mpls West unoccupied
        Wait for 1 second
    Endif

    # Station stop
    Wait for sensor Winthrop Station to become active
    Set speed to 0
    Wait for 5 seconds
    Set speed to .6

    If sensor SimMode is active
        # Move train to Watertown
        Set block Winthrop Junction occupied
        Wait for 1 second
        Set block Winthrop Station unoccupied
        Wait for 1 second
        Set block Watertown East occupied
        Wait for 1 second
        Set block Winthrop Junction unoccupied
        Wait for 1 second
    Endif

    # Clear of shared trackage, release the reservation
    Wait for block Winthrop Junction to become unoccupied
    Set sensor Reserve Open active

    If sensor SimMode is active
        # Complete train move
        Set block Watertown Station occupied
        Wait for 1 second
        Set block Watertown East unoccupied
        Wait for 1 second
    Endif

    # Station stop
    Wait for sensor Watertown Station to become active
    Set speed to 0
    Set function key 0 off
    Wait for 5 seconds
Repeat if sensor W-M Stop is inactive

Print ++++ cleanup
If sensor SimMode is active
    Set block Watertown Station unoccupied
Endif
Stop if sensor W-M Stop is active
